package com.example.leetcode;

/**
 * 动态规划
 * 使用最小花费爬楼梯
 */
public class Demo0746 {

    //动态规划
    public int minCostClimbingStairs(int[] cost) {
        int len = cost.length;
        if (len ==2){
            return Math.min(cost[0],cost[1]);
        }
        int[] fun =new int[len+1];
        fun[1]=0;
        fun[2]=Math.min(cost[0],cost[1]);

        for (int k = 3; k < len + 1; k++) {
            fun[k]=Math.min(fun[k-1]+cost[k-1],fun[k-2]+cost[k-2]);
        }

        return fun[len];
    }
}
